{% load static %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="{% static 'js/lib/layui/css/layui.css' %}">
    <link rel="stylesheet" href="{% static 'css/common.css' %}">
</head>
<body>

<div class="layui-container" style="margin-top: 30px">
    <div class="layui-row">
        <input type="text" name="model_id" id="model_id" style="display: none;" value="{{ model_obj.id }}">
        <div style="margin: 10px 0 20px;">
            <div style="margin-top: 10px;margin-bottom: 10px;">
                <label style="font-weight: bold;color: #333333">基础模型名称</label>
            </div>
            <input type="text" name="model_name" id="model_name" class="layui-input my-input" value="{{ model_obj.name }}">
        </div>
        <div style="margin: 10px 0 20px;">
            <div style="margin-top: 10px;margin-bottom: 10px;">
                <label style="font-weight: bold;color: #333333">请选择模型的类型</label>
            </div>
            <select name="model_type" id="model_type" style="width: 100%"
                    class="btn btn-default dropdown-toggle my-select">

                <option value="" style="color: gray;display: none;">请选择基础模型类型</option>
                {% if model_obj.type == "数据挖掘模型" %}
                    <option value="数据挖掘模型" selected>数据挖掘模型</option>
                {% else %}
                    <option value="数据挖掘模型">数据挖掘模型</option>
                {% endif %}

                {% if model_obj.type == "知识推理模型" %}
                    <option value="知识推理模型" selected>知识推理模型</option>
                {% else %}
                    <option value="知识推理模型">知识推理模型</option>
                {% endif %}

                {% if model_obj.type == "关联分析模型" %}
                    <option value='关联分析模型' selected>关联分析模型</option>
                {% else %}
                    <option value='关联分析模型'>关联分析模型</option>
                {% endif %}


            </select>
        </div>
    </div>

    <div>
        <button type="submit" class="my-btn" style="float: right;" id="sub"> 确认</button>
    </div>
</div>
</div>

<script type="text/javascript" src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/lib/layui/layui.js' %}"></script>
<script>
    $('#sub').click(function () {
        var model_name = $('#model_name').val();
        var model_type = $('#model_type').val();
        var model_id = $('#model_id').val();

        if (model_name === undefined) {
            alert("模型名称不能为空！！！");
        } else if (model_type === undefined) {
            alert("模型类型不能为空！！！");
        } else {
            $.ajax({
                url: '{% url 'edit_base_model' %}',
                type: 'post',
                data: {'model_id': model_id, 'model_name': model_name, 'model_type': model_type},
                success: function (res) {
                    if (res["code"] == "1") {
                        window.parent.layer.closeAll();
                        window.parent.location.reload();
                    } else {
                        alert(res["msg"]);
                    }
                }
            })
        }
    });
</script>

</body>
</html>